//
//  THIconChangedViewController.m
//  TreeHole
//
//  Created by apple on 2020/9/1.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THIconChangedViewController.h"

@interface THIconChangedViewController ()
@property(nonatomic, strong) UIImageView                     *iconImageView;/**<  */
@end

@implementation THIconChangedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置头像";
    [self stoneobs_ui_configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    THUserModel * userModel = STTools_UserManger.defult.stoneobs_fun_get_loginedUser;
    UIView * header = [[UIView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    
    UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_WIDTH)];
    [stoneobs_ui_imageView sd_setImageWithURL:userModel.header_img.mj_url];
    [header addSubview:stoneobs_ui_imageView];
    self.iconImageView = stoneobs_ui_imageView;
    __weak typeof(self) weakSelf =  self;
    
    ({
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(15, stoneobs_ui_imageView.bottom + 20, UISCREEN_WIDTH - 30, 40)
                                                                  title:@"拍照"
                                                             titleColor:UIColor.whiteColor
                                                              titleFont:15
                                                           cornerRadius:20
                                                        backgroundColor:WH_UICOLOR_FROM_RGBA(0x333333)
                                                        backgroundImage:nil
                                                                  image:nil];
        stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [header addSubview:stoneobs_ui_button];
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [weakSelf stoneobs_fun_st_showTakePhotoImagePicker:^(UIImage *image) {
                [TMQNUploadManger.manger sendQiNiuWithImage:image handle:^(NSString * _Nonnull url) {
                    if (url.length) {
                        if (weakSelf.didChangedIcon) {
                            weakSelf.didChangedIcon(url);
                        }
                        weakSelf.iconImageView.image = image;
                    }
                    
                }];
               
            }];
        }];
    });

    
    ({
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(15, stoneobs_ui_imageView.bottom + 80, UISCREEN_WIDTH - 30, 40)
                                                                  title:@"从相册选择一张"
                                                             titleColor:WH_UICOLOR_FROM_RGBA(0x333333)
                                                              titleFont:15
                                                           cornerRadius:20
                                                        backgroundColor:nil
                                                        backgroundImage:nil
                                                                  image:nil];
        stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [stoneobs_ui_button stbw_setBorderWith:1 borderColor:WH_UICOLOR_FROM_RGBA(0xD9D9D9) cornerRadius:20];
        [header addSubview:stoneobs_ui_button];
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [weakSelf stoneobs_fun_st_showchosePhotoImagePicker:^(UIImage *image) {
                //上传图片
                [TMQNUploadManger.manger sendQiNiuWithImage:image handle:^(NSString * _Nonnull url) {
                    if (url.length) {
                        if (weakSelf.didChangedIcon) {
                            weakSelf.didChangedIcon(url);
                        }
                        weakSelf.iconImageView.image = image;
                    }
                    
                }];
            }];
        }];
        
        header.height = stoneobs_ui_button.bottom;
        self.tableView.tableHeaderView = header;
    });
}

@end
